const path = require('path');
module.exports = {
  telemetry: false,
  // Global page headers (https://go.nuxtjs.dev/config-head)
  head: {
    title: 'vblog',
    meta: [{
        charset: 'utf-8'
      },
      {
        name: 'viewport',
        content: 'width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0'
      },
      {
        hid: 'description',
        name: 'description',
        content: '小赫兹'
      },
      {
        name: 'keywords',
        content: 'blog'
      },
      {
        name: 'renderer',
        content: 'webkit'
      }
    ],
    link: [{
      rel: 'icon',
      type: 'image/x-icon',
      href: '/favicon.ico'
    }, {
      rel: 'stylesheet',
      href: '//at.alicdn.com/t/font_1579827_em62m137c84.css'
    }]
  },
  /*
   ** Customize the progress-bar color
   */
  loading: {
    color: '#fff'
  },
  // Global CSS (https://go.nuxtjs.dev/config-css)
  css: [
    './static/global.css',
    'github-markdown-css/github-markdown.css',
    {
      src: './assets/css/element-variables.scss',
      lang: 'scss'
    }
  ],

  // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
  plugins: [
    '@/plugins/element-ui',
    '~/plugins/axios',
    '~/plugins/filters',
    '~/assets/icons/index',
  ],

  // Auto import components (https://go.nuxtjs.dev/config-components)
  components: true,

  // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  buildModules: [],

  // Modules (https://go.nuxtjs.dev/config-modules)
  modules: ['@nuxtjs/style-resources', '@nuxtjs/axios'],
  styleResources: {
    scss: './assets/css/common.scss'
  },
  // Build Configuration (https://go.nuxtjs.dev/config-build)
  build: {
    transpile: [/^element-ui/],
    extend(config, {
      isDev,
      isClient
    }) {
      // 排除 nuxt 原配置的影响,Nuxt 默认有vue-loader,会处理svg,img等
      // 找到匹配.svg的规则,然后将存放svg文件的目录排除
      const svgRule = config.module.rules.find(rule => rule.test.test('.svg'))
      svgRule.exclude = [path.resolve(__dirname, 'assets/icons/svg')];
      config.module.rules.push({
        test: /\.md$/,
        use: [{
            loader: 'html-loader'
          },
          {
            loader: 'markdown-loader',
            options: {}
          }
        ],
      }, {
        test: /\.svg$/, //匹配.svg
        include: [path.resolve(__dirname, 'assets/icons/svg')], //将存放svg的目录加入到loader处理目录
        use: [{
          loader: 'svg-sprite-loader',
          options: {
            symbolId: 'icon-[name]'
          }
        }]
      })
    }
  },
  server: {
    port: 7070,
    host: 'localhost'
  },
  router: {
    middleware: [],
    extendRoutes(routes, resolve) {
      routes.push({
        path: '/index',
        component: resolve(__dirname, 'pages/main/index.vue')
      })
    }
  },

}
